/*
 * Copyright (C) 2012 rothens
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package rpg.gfx;

import java.awt.event.KeyEvent;
import rpg.RPG;

/**
 *
 * @author rothens
 */
public class MessageScreen extends Bitmap {
	
	Bitmap t = null;
	
	
	public MessageScreen(String text, int color, byte id, int spacing){
		super(RPG.WINDOW_WIDTH, RPG.WINDOW_HEIGHT);
		processText(text, color, id, spacing);
	}
	
	public void processText(String text, int color, byte id, int spacing){
		String[] lines = text.split("##");
		Bitmap[] drawed = new Bitmap[lines.length];
		int maxWidth = 0;
		int textHeight = 0;
		
		for(int i = 0; i < lines.length; i++){
			drawed[i] = RPG.fs.getText(lines[i], id, color);
			if(drawed[i].width>maxWidth) maxWidth=drawed[i].width;
			if(textHeight == 0) textHeight = drawed[i].height;
		}
		
		if(maxWidth == 0 || textHeight == 0) return;
		
		t=new Bitmap(maxWidth, textHeight*drawed.length+spacing*drawed.length-1);
		int y = 0;
		for(Bitmap b : drawed){
			t.draw(b, t.width/2-b.width/2, y);
			y+=b.height+spacing;
		}
	}
	
	public void tick(){
		if(RPG.keylistener.isKeyDown(KeyEvent.VK_ENTER) ||
			RPG.keylistener.isKeyDown(KeyEvent.VK_SPACE)){
			skip();
		}
	}
	
	public void render(){
		clearWith(0x0);
		draw(t,width/2-t.width/2, height/2-t.height/2);
	}
	
	/**
	 * This is called when the user presses enter or space
	 */
	public void skip(){
		
	}
	
}
